window.onload = function () {
  var oUser = document.getElementById("username");
  var oPwd = document.getElementById("password");
  var oBtn = document.getElementById("btn");
  //
  //
  //
  var sjhm = document.querySelector(".sjhm");
  var szmm = document.querySelector(".szmm");
  var qrmm = document.querySelector(".qrmm");
  var ljzc = document.querySelector(".ljzc");
  ljzc.onclick = function () {
    var upData = null;
    var repeat = null;
    if (sjhm.value && szmm.value) {
      if (window.localStorage.getItem("list")) {
        upData = { username: sjhm.value, password: szmm.value };
        var dataJson = window.localStorage.getItem("list");
        dataJson = eval("(" + dataJson + ")");
        for (var i = 0; i < dataJson.length; i++) {
          if (dataJson[i].username == upData.username) {
            alert("用户名重复");
            repeat = 1;
          }
        }
        if (repeat == null && szmm.value == qrmm.value) {
          alert("注册成功");
          dataJson.push(upData);
          dataJson = JSON.stringify(dataJson);
          window.localStorage.setItem("list", dataJson);
          console.log(window.localStorage.getItem("list"));
        } else {
          alert("两次密码不一样");
        }
      } else {
        upData = { username: sjhm.value, password: szmm.value };
        console.log(upData);
        var data = [];
        data.push(upData);
        data = JSON.stringify(data);
        window.localStorage.setItem("list", data);
        alert("注册成功");
        console.log(window.localStorage.getItem("list"));
      }
    }
  };
};
